package com.roger.uia.helper.manager;

import android.accounts.AccountManager;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.util.Log;

import java.util.Arrays;

public class Account {
    private static final String TAG = "Test" + Account.class.getSimpleName();
    private AccountManager accountManager = (AccountManager)InstrumentationRegistry.getTargetContext().getSystemService(Context.ACCOUNT_SERVICE);

    public static Account acc(){ return new Account(); }

    public boolean hasAccount(String account) {
        android.accounts.Account[] accounts = accountManager.getAccounts();
        Log.d(TAG,"CurrentAccounts:"+ Arrays.toString(accounts));
        for (android.accounts.Account a : accounts) {
            if (a.type.contains(account)||a.name.contains(account)) return true;
        }
        return false;
    }

    public boolean hasGoogleAccount(){
        return hasAccount("google");
    }

    public boolean hasPopAccount(){
        return hasAccount("pop3");
    }

    public boolean hasImapAccount(){ return hasAccount("imap"); }

    public boolean hasExchangeAccount(){
        return hasAccount("exchange");
    }

}
